module PrismBreak {

    export class ViewManager {
        private frameworkApp: PbApp;
        private Views: View[];

        constructor(frameworkApp?: PbApp) {
            this.frameworkApp = frameworkApp;
            this.Views = [];

        }

        public ActivateView(view: View): void {
            //view.Region.AddView(view);

            view.Region.SetActiveView(view);

            var jnode = $(view.Node);

            jnode.removeClass(PrismBreak.ViewClass[PrismBreak.ViewClass.pb_invisible]);

            if (!jnode.hasClass(PrismBreak.ViewClass[PrismBreak.ViewClass.pb_visible])) {
                jnode.addClass(PrismBreak.ViewClass[PrismBreak.ViewClass.pb_visible]);
            }

            view.Activate();

        }

        public ActivateViewById(id: string): void {
            var view = this.GetViewById(id);

            if (view) {
                this.ActivateView(view);
            }

        }

        public DeactivateView(view: View): void {

            var jnode = $(view.Node);

            jnode.removeClass(PrismBreak.ViewClass[PrismBreak.ViewClass.pb_visible]);

            if (!jnode.hasClass(PrismBreak.ViewClass[PrismBreak.ViewClass.pb_invisible])) {
                jnode.addClass(PrismBreak.ViewClass[PrismBreak.ViewClass.pb_invisible]);
            }
            view.Deactivate();

        }

        public AddView(view: View): void {

            this.Views.push(view);

        }

        public RemoveView(view: View): void {

            var index = this.Views.indexOf(view);

            this.Views.splice(index, 1);

        }

        public GetViewById(viewId: string): View {

            var view: View = Enumerable.From(this.Views)
                .Where((item: View) => {
                    return item.Id === viewId;
                }).SingleOrDefault(null);

            return view;

        }

    }
}